/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.game.entity.pickup;

import ace.game.Sprite;
import ace.game.entity.Entity;
import ace.geometry.Vertex2D;
import ace.system.StateManager;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Hallucinogen
 */
public class Pickup extends Entity {
    protected Pickup() {
		//Initialize
		position    = new Vertex2D();
        mActive     = true;
	}

	public Pickup(PickupData data, Vertex2D inPos) {
		//Initialize
		this();

		//Initialize data
        position    = inPos;
		mData       = data;
	}

	public PickupData getData()	{	return mData;   }
    public boolean isActive()   {   return mActive; }

	public void update(long time) {
		mData.getSprite().update(time);
    }

    public void picked() {
        mActive = false;
    }

	public void draw(Graphics g, int startX, int startY, int endX, int endY) {
		//Get current sprite
		Sprite Current = mData.getSprite();
		if (Current == null) return;

		//Get rect
		int Left	= (int)(position.x - startX);
		int Top		= (int)(position.y - startY);

		//Ensure in drawing area
		if (Left + Current.getWidth() < 0)					return;
		else if(Left > StateManager.instance().getWidth())	return;
		else if (Top + Current.getHeight() < 0)				return;
		else if (Top > StateManager.instance().getHeight())	return;

		//Draw sprite
		Current.setPosition(Left, Top);
		Current.draw(g, Graphics.VCENTER | Graphics.HCENTER);
	}

	// Data
	protected PickupData mData;

    private boolean mActive;
}
